package com.uuuo.mvp;

import android.app.ProgressDialog;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.uuuo.mvp.base.BaseMVPActivity;
import com.uuuo.mvp.entity.UserInfo;
import com.uuuo.mvp.userinfo.IUserInfoContract;
import com.uuuo.mvp.userinfo.UserInfoPresenter;

public class MainActivity extends BaseMVPActivity<UserInfoPresenter> implements IUserInfoContract.IUserInfoView {
    private EditText edt_username, edt_pwd;
    private Button btn_clear, btn_login;
    private ProgressDialog progressDialog;

    @Override
    protected void setContentView() {
        setContentView(R.layout.activity_main);
    }

    @Override
    protected UserInfoPresenter createPresenter() {
        return new UserInfoPresenter();
    }

    @Override
    protected void initView() {
        edt_username = (EditText) findViewById(R.id.edt_username);
        edt_pwd = (EditText) findViewById(R.id.edt_pwd);

        btn_clear = (Button) findViewById(R.id.btn_clear);
        btn_login = (Button) findViewById(R.id.btn_login);

        btn_clear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        btn_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getPresenter().getUsers();
            }
        });

        progressDialog = new ProgressDialog(MainActivity.this);//1.创建一个ProgressDialog的实例
        progressDialog.setMessage("正在加载中，请稍等......");//3.设置显示内容
        progressDialog.setCancelable(false);//4.设置可否用back键关闭对
    }

    @Override
    protected void initData() {

    }

    @Override
    public void onLoading() {
        progressDialog.show();
    }

    @Override
    public void onError() {
        progressDialog.hide();
        Toast.makeText(this, "获取用户信息错误", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onSucceed(UserInfo userInfo) {
        progressDialog.hide();
        Toast.makeText(this, userInfo.toString(), Toast.LENGTH_SHORT).show();
    }
}
